package 锁;
//如果有多个wait 但是只有一个notify（前提锁对象都相同），那么就会随机唤醒一个
public class Demo_8 {
    static Object A = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{

            synchronized (A){
                try {
                    A.wait();
                    System.out.println("t1 被唤醒");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

        });

        Thread t2 = new Thread(()->{
            synchronized (A){
                try {
                    A.wait();
                    System.out.println("t2 被唤醒");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Thread t3 = new Thread(()->{
            synchronized (A){
                try {
                    A.wait();
                    System.out.println("t3 被唤醒");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

//        Thread t4 = new Thread(()->{
//            synchronized (A){
//                try {
//                    Thread.sleep(1000);
//                    A.notify();
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//
//            }
//        });

        Thread t4 = new Thread(()->{
            synchronized (A){
                try {
                    Thread.sleep(1000);
                    A.notifyAll();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        });
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
